package cn.bugstack.springframework.beans.factory.support;

import cn.bugstack.springframework.beans.BeanException2;
import cn.bugstack.springframework.beans.factory.config.BeanDefinition2;

import java.util.HashMap;
import java.util.Map;

public class DefaultListableBeanFactory2 extends AbstractAutowireCapableBeanFactory2 implements BeanDefinitionRegistry2{

    private Map<String, BeanDefinition2> beanDefinitionMap = new HashMap<>();

    @Override
    public void registerBeanDefinition(String name, BeanDefinition2 beanDefinition2) {
        beanDefinitionMap.put(name,beanDefinition2);
    }

    @Override
    protected BeanDefinition2 getBeanDefinition(String name) throws BeanException2 {
        BeanDefinition2 beanDefinition2 = beanDefinitionMap.get(name);
        if (beanDefinition2 == null) throw new BeanException2("No bean named '"+name+"' is defined");
        return beanDefinition2;
    }
}
